<template>
	<view class="page-body">
		<view class="top-box u-p-0">
			<view class="navbar u-flex u-p-l-25">
				<u-icon @click="goBack" name="arrow-left"></u-icon>
			</view>

			<!-- 待打款 -->
			<view class="status-box u-flex u-row-center u-col-center " v-if="orderInfo.margin_audit_status===0">
				<image class="status-img  u-p-r-10" :src="'../../static/channel/images/bond/dakuan.png'"></image>
				<view class="status-txt u-p-l-10">待打款</view>
			</view>
			<!-- 待打款 -->
			<view class="status-box u-flex u-row-center u-col-center " v-if="orderInfo.margin_audit_status===1">
				<image class="status-img  u-p-r-10" :src="'../../static/channel/images/bond/shenhe.png'"></image>
				<view class="status-txt u-p-l-10">待确认</view>
			</view>
			<!-- 待打款 -->
			<view class="status-box u-flex u-row-center u-col-center " v-if="orderInfo.margin_audit_status===2">
				<image class="status-img  u-p-r-10" :src="'../../static/channel/images/bond/jiangli.png'"></image>
				<view class="status-txt u-p-l-10">已返</view>
			</view>
			<!-- 待打款 -->
			<view class="status-box u-flex u-row-center u-col-center " v-if="orderInfo.margin_audit_status===3 ||orderInfo.margin_audit_status===4">
				<image class="status-img  u-p-r-10" :src="'../../static/channel/images/bond/fanhuan.png'"></image>
				<view class="status-txt u-p-l-10">确认失败</view>
			</view>
		</view>
		<view v-if="orderInfo.purchase_type == 1" class="purchase_box">
			<view class="type">
				<u-tag class="u-m-r-20" text="退还" color="#F06C50" border-color="#F06C50" mode="plain" size="mini" />
				我的保证金退还订单
			</view>
			<text class="tip mt20">我的保证金,在向上级进货时将以每件商品的差价退还</text>
		</view>
		

		<!-- 地址 -->
		<view v-if="orderInfo.purchase_type > 1">

			<view class="address-content u-flex u-p-l-20 bg-white">
				<view class="map-icon u-m-r-20">
					<u-icon name="map-fill" color="#fff" size="48" top="8"></u-icon>
				</view>
				<view class="cen u-flex-1">
					<view class="top">
						<text class="name">{{orderInfo.consignee}}</text>
						<text class="mobile">{{orderInfo.mobile}}</text>
					</view>
					<text class="address">{{orderInfo.merger_name}} {{orderInfo.address}}</text>
				</view>
			</view>
		</view>

		<!-- <view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">订单状态</text>
				<text class="cell-tip red">{{orderInfo.ostatus}}</text>
			</view>
		</view> -->

		<!-- 保证金退还人信息 -->
		<view class="yt-list mt20">
			<view class="yt-list-cell b-b">
				<text class=" clamp u-font-xl">保证金退还人信息</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">上级退还人</text>
				<view class="cell-tip"><text>{{orderInfo.supply_name}}</text></view>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">用户ID</text>
				<view class="cell-tip"><text>{{orderInfo.supply_uid}}</text></view>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">手机号</text>

				<text class="cell-tip" v-if="orderInfo.user">{{orderInfo.user.supply_mobile}}</text>
			</view>
			<view class="yt-list-cell "  v-if="orderInfo.margin_audit_status==1 ||orderInfo.margin_audit_status==2">
				<text class="cell-tit clamp">上传凭证</text>
			</view>
			<view class="yt-list-cell b-b"  v-if="orderInfo.margin_audit_status==1 ||orderInfo.margin_audit_status==2">
				<view class="offlineimg_item" v-for="(pic, index) in orderInfo.margin_audit_img" :key="index">
					<image :src="baseUrl+pic" @click="app.showImg(offlineimgList,index)"></image>
				</view>
			</view>

			<view class="yt-list-cells" v-if="orderInfo.margin_audit_status===4">
				<text class="cell-tit">
					未通过原因：{{orderInfo.margin_audit_error}}
				</text>
			</view>
			<view class="yt-list-cell">
			</view>

		</view>
		<view class="yt-list mt20">
			<view class="yt-list-cell b-b">
				<text class=" clamp u-font-xl">退还金额</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">保证金总金额</text>
				<view class="cell-tip"><text>¥{{orderInfo.earnest_money_total}}</text></view>
			</view>

			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">本次退还</text>
				<view class="cell-tip"><text>¥{{orderInfo.balance_deduction}}</text></view>
			</view>

			<view class="yt-list-cell">
			</view>

		</view>

		<view class="goods-section">
			<view class="yt-list-cell b-b" style="margin-bottom: -40rpx;">
				<text class="cell-tit clamp">相关进货订单</text>
			</view>
			<!-- 商品列表 -->
			<view class="g-item u-border-bottom" v-for="(item, index) in orderInfo.goodsList" :key="item.rec_id">
				<image :src="baseUrl+item.pic"></image>
				<view class="right">
					<text class="title ">{{item.goods_name}}</text>
					<view class="spec">{{item.sku_name}}</view>
					<view class="price-box u-flex">
						<text class="price u-flex-1"><text class="rmb">￥</text>{{item.sale_price}}</text>
						<text class="number">x{{item.goods_number}}{{item.goods_unit_name}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 金额明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">商品数量</text>
				<text class="cell-tip">{{total_num}}件</text>
			</view>

			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">商品金额</text>
				<text class="cell-tip">￥{{orderInfo.goods_amount}}</text>
			</view>


			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">付款金额</text>
				<text class="cell-tip gold-color">￥{{orderInfo.order_amount}}</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">订单编号</text>
				<text class="cell-tip">{{orderInfo.order_sn}}</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">创建时间</text>
				<text class="cell-tip">{{orderInfo._add_time}}</text>
			</view>
			<!-- <view class="yt-list-cell desc-cell">
				<text class="cell-tit clamp">备注</text>
				<rich-text :nodes="orderInfo.buyer_message"></rich-text>
			</view> -->
		</view>

		<!-- action-box  u-margin-top-60 u-flex u-row-right -->
		<!-- 商品列表 -->
		<view class="action-box u-margin-top-30 u-flex u-row-right">
			<button v-if="orderInfo.is_user==1  && orderInfo.margin_audit_status!=2 " class="action-btn block grey_1" @click="dialTel(orderInfo.user.supply_mobile)">联系上级</button>
			<button v-if="orderInfo.is_user==1  && orderInfo.margin_audit_status!=2" class="action-btn block  grey_1" @click="cfmCodPay(3)">未收到打款</button>
			<button v-if="orderInfo.is_user==1 && orderInfo.margin_audit_status!=2" class="action-btn block grey_2"
				@click="cfmCodPay(2)">确认收款</button>

			<button v-if="orderInfo.is_user==2" class="action-btn block grey_1" @click="dialTel(orderInfo.mobile)">联系下级</button>
			<button v-if="orderInfo.is_user==2  && orderInfo.margin_audit_status!=2 && orderInfo.margin_audit_status!=1" class="action-btn block grey_1" @click="showCheckPay=true">审核未通过</button>
			<button v-if="orderInfo.is_user==2  && orderInfo.margin_audit_status!=2 && orderInfo.margin_audit_status!=1" class="action-btn block grey_2"  @click="app.goPage('/pagesB/channel/bond/grid?order_id='+orderInfo.order_id+'&type=2')">去打款</button>

		</view>
		<u-modal v-model="showCheckPay" title="审核未通过原因" confirm-text="我写好了" :mask-close-able="true"
			:confirm-style="{height:'80rpx',lineHeight:'80rpx',margin:'20rpx 140rpx',background:'#C39F4F',borderRadius:'40rpx',color:'#fff'}"
			@confirm="reject">
			<view class="slot-content mt20 p20">
				<u-field class="reject-input" label-width="0" :clearable="false" v-model="remark"
					placeholder="请输入审核未通过原因，或者需要修改的地方" type="textarea" maxlength="50">
				</u-field>
				<view class="count">{{remark.length}}/50</view>
			</view>
		</u-modal>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.config.baseUrl,
				order_id: 0,
				orderInfo: {},
				showCheckPay: false,
				remark: '',
				showShipping: false,
				shippingListShow: false,
				shipping_name: '请选择快递',
				shipping_id: 0,
				shippinglist: [],
				invoice_no: '',
				offlineimgList: [],
				total_num: 0,
				sub_msg: '',
				statusImgs: [

				]
			}
		},
		onLoad(option) {
			let order_id = parseInt(option.order_id);
			if (isNaN(order_id) == true || order_id < 1) {
				this.app.showModal('订单ID传值错误.', '/pagesB/channel/center/index', true);
				return false;
			}
			this.order_id = order_id;
		},
		onShow() {
			this.getOrderInfo();
		},
		methods: {
			dialTel(tel){
				console.log(tel)
				uni.makePhoneCall({
				    phoneNumber: tel //仅为示例
				});
			},
			getOrderInfo() {
				this.$u.post('channel/api.order/info', {
					order_id: this.order_id,
					type: 1
				}).then(res => {
					this.orderInfo = res.data;
					let that = this;
					this.orderInfo.margin_audit_img.forEach(url => {
						that.offlineimgList.push(that.config.baseUrl + url);
					})
					this.calcTotalNum();
				}).catch(res => {})
			},
			//计算总数
			calcTotalNum() {
				let total = 0;
				this.orderInfo.goodsList.forEach(item => {
					total += item.goods_number;
				})
				this.total_num = total;
			},
			//取消订单
			cancelOrder() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定取消订单？',
					showCancel: true,
					confirmText: '确定取消',
					cancelText: '放弃取消',
					success: function(res) {
						if (res.confirm) {
							that.$u.post('channel/api.order/cancel', {
								order_id: that.order_id
							}).then(res => {
								that.getOrderInfo();
							})
						}
					}
				});
			},
			reject() {
				this.cfmCodPay(4);
			},
			cfmCodPay(operate) {

				let that = this;
				if (operate == 2) {
					this.sub_msg = "确认已收到款项？操作后无法撤回.";
				} else if (operate == 3) {
					this.sub_msg = "确认未收到款项？操作后无法撤回.";
				} else if (operate == 4) {
					if (this.remark.length < 8) {
						return this.$u.toast('未审核通过,备注长度不能少于8个字符.');
					}
					this.sub_msg = "确认未审核通过？操作后无法撤回.";
				}
				uni.showModal({
					title: '提示',
					content: this.sub_msg,
					showCancel: true,
					success: function(res) {
						that.showCheckPay = false;
						if (res.confirm) {
							that.$u.post('channel/api.order/returnBond', {
								order_id: that.order_id,
								remark: that.remark,
								status: operate,
								
							}).then(res => {
								uni.showToast({
									title: res.msg,
									icon: 'none',
								});
								setTimeout(function() {
									that.getOrderInfo();
								}, 2000);


							})
						}
					}
				});
			},
			showShippingBox() { //点击选择快递
				if (this.shippinglist.length < 1) {
					this.$u.post('channel/api.order/getShippingList').then(res => {
						this.shippinglist = res.data;
					})
				}
				this.showShipping = true;
			},
			confirmShipping(e) { //确定选择快递
				this.shipping_name = e[0].label;
				this.shipping_id = e[0].value;
			},
			postShipping() { //提交发货
				if (this.shipping_id < 1) {
					return this.$u.toast('请选择快递公司.');
				}
				if (this.invoice_no.length < 5) {
					return this.$u.toast('请输入快递单号.');
				}
				this.$u.post('channel/api.order/postShipping', {
					order_id: this.order_id,
					shipping_id: this.shipping_id,
					invoice_no: this.invoice_no
				}).then(res => {
					this.getOrderInfo();
				})
			},
			cmfSing() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认已收到商品？操作后无法撤回.',
					showCancel: true,
					success: function(res) {
						that.showCheckPay = false;
						if (res.confirm) {
							that.$u.post('channel/api.order/sign', {
								order_id: that.order_id,
							}).then(res => {
								that.getOrderInfo();
							})
						}
					}
				});
			},
			goBack() {
				uni.navigateBack();
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
		padding-bottom: 100rpx;
	}
	::v-deep .uicon-arrow-left {
		// color: #19BE6B !important;
		color: #ffff !important;
	}

	.purchase_box {
		background-color: #FFFFFF;
		padding: 40rpx 20rpx;
		margin-bottom: 20rpx;

		.type {
			font-size: 28rpx;
		}

		.tip {
			display: block;
			color: #999999;
			font-size: 20rpx;
		}
	}

	.action-box {
		padding: 20rpx;
		background: #FFFFFF;
	}

	.grey_1 {
		color: #86869C;
		border: 1rpx solid #86869C;

	}

	.grey_2 {
		color: #C39F4F;
		border: 1rpx solid #C39F4F;
	}

	.address-content {
		align-items: center;
		padding: 20rpx;
		display: flex;

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28rpx;
			color: $font-color-dark;
		}

		.name {
			margin-right: 24rpx;
		}

		.mobile {
			color: #999;
		}

		.address {
			margin-top: 16rpx;
			margin-right: 20rpx;
			word-break: break-all;
		}


	}


	.goods-section {
		margin-top: 16rpx;
		padding-top: 10rpx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84rpx;
			padding: 0 30rpx;
			// position: relative;
		}

		.logo {
			display: block;
			width: 50rpx;
			height: 50rpx;
			border-radius: 100px;
		}

		.name {
			font-size: 30rpx;
			color: $font-color-dark;
			margin-left: 24rpx;
		}

		.g-item {
			display: flex;
			padding: 40rpx 20rpx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140rpx;
				height: 140rpx;
				border-radius: 4rpx;
			}

			.right {
				flex: 1;
				padding-left: 24rpx;
				overflow: hidden;
			}

			.title {
				display: block;
				font-size: 30rpx;
				color: $font-color-dark;
				height: 100rpx;
				margin-bottom: 30rpx;
			}

			.price-box {
				font-size: 32rpx;
				color: $font-color-dark;
				display: flex;

				.spec {
					flex: 1;
					font-size: 26rpx;
					color: $font-color-light;
				}

				.price {
					font-size: 36rpx;
					margin-bottom: 4rpx;

					.rmb {
						font-size: 24rpx;
					}
				}

				.number {
					font-size: 24rpx;
					color: #666;
					margin-left: 20rpx;
				}
			}

			.step-box {
				// position: relative;
			}
		}
	}

	.yt-list {
		background: #fff;
	}

	.yt-list-cells {
		background: #F3F3F3;
		border-radius: 12rpx;
		margin: 10rpx 30rpx 10rpx 40rpx;
		padding-bottom: 10rpx;

		.cell-tit {
			display: flex;
			justify-content: center;
			padding: 20rpx;
			line-height: 40rpx;
			font-size: 28rpx;


		}

	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10rpx 30rpx 10rpx 40rpx;
		line-height: 70rpx;
		// position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30rpx;
		}

		.cell-icon {
			height: 32rpx;
			width: 32rpx;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 32rpx;
			background: #f85e52;
			border-radius: 4rpx;
			margin-right: 12rpx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24rpx;
			color: $font-color-light;
			margin-left: 8rpx;
			margin-right: -10rpx;
		}

		.cell-tit {
			flex: 1;
			font-size: 28rpx;
			margin-right: 10rpx;
		}

		.cell-tip {
			font-size: 28rpx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color
			}

			&.red {
				color: $font-color-base;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90rpx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}

		.remark {
			background: #f3f3f3;
			word-break: break-all;
			font-size: 28rpx;
			color: #999999;
			line-height: 40rpx;
			padding: 20rpx;
			border-radius: 12rpx;
		}
	}

	.offlineimg_item {
		image {
			flex-shrink: 0;
			width: 140rpx;
			height: 140rpx;
			border-radius: 4rpx;
			margin-right: 10rpx;
		}
	}

	.popup_box {
		padding: 0rpx 20rpx;

		.title {
			display: flex;
			height: 100rpx;
			align-items: center;
			font-weight: 700;
			font-size: 32rpx;
		}

		.input {
			padding: 20rpx;
		}
	}

	.top-box {
		height: 268rpx;
		// background: linear-gradient(221deg, #F1D9AA 0%, #BE9453 100%);
		background: linear-gradient(221deg, #EA7F2A 0%, #E93E3E 100%);

		.navbar {
			height: 88rpx;
			background: transparent;
			box-shadow: none;
		}

		.status-box {
			text-align: center;
			height: 180rpx;

			.status-img {
				width: 36rpx;
				height: 36rpx;
			}

			.status-txt {
				color: #744700;
				font-size: 42rpx;
			}
		}
	}

	.map-icon {
		width: 66rpx;
		height: 66rpx;
		background: #C39F4F;
		border-radius: 50%;
		text-align: center;
		line-height: 66rpx;
	}

	.reject-input {
		height: 240rpx;
		background: #F0F0F5;
		border-radius: 12rpx;
	}

	.b-b:after {
		border-bottom: 0px solid #F2F2F2 !important;
	}

	.slot-content {
		position: relative;

		.count {
			position: absolute;
			bottom: 30rpx;
			right: 40rpx;
			color: #86869C;
			font-size: 24rpx;
		}
	}
</style>
